#import "TopicCell.h"
#import "UIImageView+WebCache.h"
#import "NetWorkManager.h"

@implementation TopicCell

@synthesize judgeText;
@synthesize imgView;
@synthesize titleView;

-(id)init{
    self = [super init];
    if (self) {
        //
    }
    return self;
}

- (void)dealloc
{
    PP_RELEASE(imgView);
    PP_RELEASE(titleView);
    PP_RELEASE(judgeText);
    PP_RELEASE(topicRealImg);
    PP_RELEASE(cellBg);
    PP_RELEASE(judgeTime);
    [super dealloc];
}

-(void)setTopic:(NSString *)topicTitle andImg:(UIImage *)topicImg andSammry:(NSString *)topicsText andTime:(NSString *)topicTime andUrl:(NSString *)topicUrl {
    titleView.text = topicTitle;
    judgeTime.text = topicTime;
    
    if (PP_hasWifi || PP_HasNoWifiButLoadImages) {
        [topicRealImg setImageWithURL:[NSURL URLWithString:topicUrl]
                     placeholderImage:[UIImage imageNamed:@"topic_default_photo.png"]];
    }else{
        topicRealImg.image = [UIImage imageNamed:@"topic_default_photo.png"];
    }
    
    CGRect textFrame = judgeText.frame;
    judgeText.text = topicsText;
    //textFrame.size.height = textView.contentSize.height;
    self.judgeText.frame = textFrame;
    [self judgeAlignTop];
}

- (void)judgeAlignTop {
    CGSize fontSize = [self.judgeText.text sizeWithFont:self.judgeText.font];
    double finalHeight = fontSize.height * self.judgeText.numberOfLines;
    double finalWidth = self.frame.size.width;    //expected width of label
    CGSize theStringSize = [self.judgeText.text sizeWithFont:self.judgeText.font constrainedToSize:CGSizeMake(finalWidth, finalHeight) lineBreakMode:self.judgeText.lineBreakMode];
    int newLinesToPad = (finalHeight  - theStringSize.height) / fontSize.height;
    for(int i=0; i<newLinesToPad; i++){
        self.judgeText.text = [self.judgeText.text stringByAppendingString:@"\n  "];
    }
}

//- (void)alignBottom {
//    CGSize fontSize = [self.text sizeWithFont:self.font];
//    double finalHeight = fontSize.height * self.numberOfLines;
//    double finalWidth = self.frame.size.width;    //expected width of label
//    CGSize theStringSize = [self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(finalWidth, finalHeight) lineBreakMode:self.lineBreakMode];
//    int newLinesToPad = (finalHeight  - theStringSize.height) / fontSize.height;
//    for(int i=0; i<newLinesToPad; i++)
//        self.text = [NSString stringWithFormat:@" \n%@",self.text];
//}


@end
